import type { CreateCrudOptionsRet } from '@fast-crud/fast-crud';

import type { DefAreaModel } from '#/api';

import { DefAreaApi } from '#/api';
import { DictEnum } from '#/enums/commonEnum';
import { $t } from '#/locales';
import { backendDict, STATE_CONSTANT_DICT } from '#/plugins/fast-crud/common';

export function createCrudOptions(): CreateCrudOptionsRet<DefAreaModel.DefAreaResultVO> {
  return {
    crudOptions: {
      request: {
        addRequest: DefAreaApi.addRequest,
        editRequest: DefAreaApi.editRequest,
      },
      form: {
        // 单列布局
        col: { span: 24 },
      },
      addForm: { mode: 'add' },
      editForm: { mode: 'edit' },
      columns: {
        id: {
          title: 'id',
          form: { show: false },
          type: 'text',
        },
        parentId: {
          title: 'parentId',
          form: { show: false },
          type: 'text',
        },
        parentName: {
          title: '上级节点',
          type: 'text',
          form: {
            component: { disabled: true },
            value: '根节点',
          },
        },
        code: {
          title: $t('devOperation.system.defArea.code'),
          type: 'text',
        },
        name: {
          title: $t('devOperation.system.defArea.name'),
          type: 'text',
        },
        fullName: {
          title: $t('devOperation.system.defArea.fullName'),
          type: 'text',
        },
        level: {
          title: $t('devOperation.system.defArea.level'),
          dict: backendDict(DictEnum.AREA_LEVEL),
          addForm: {
            value: '10',
          },
          type: 'dict-radio',
        },
        source: {
          title: $t('devOperation.system.defArea.source'),
          dict: backendDict(DictEnum.AREA_SOURCE),
          type: 'dict-radio',
        },
        longitude: {
          title: $t('devOperation.system.defArea.longitude'),
          type: 'text',
          form: { col: { span: 12 } },
        },
        latitude: {
          title: $t('devOperation.system.defArea.latitude'),
          type: 'text',
          form: { col: { span: 12 } },
        },
        state: {
          title: $t('devOperation.system.defArea.state'),
          dict: STATE_CONSTANT_DICT,
          addForm: { value: true },
          type: 'dict-radio',
          form: { col: { span: 12 } },
        },
        sortValue: {
          title: $t('devOperation.system.defArea.sortValue'),
          type: 'number',
          form: { col: { span: 12 } },
        },
      },
    },
  };
}
